import java.nio.ByteBuffer;
import java.util.Arrays;

//import java.net.InetAddress;
//import java.net.UnknownHostException;

public class Tester {

    public static void main(String[] args) {

        MacAddress address1 = new MacAddress();

        byte[] testAddress = { 127, -128, -128, -112, 0, 0 };
        MacAddress address2 = new MacAddress(testAddress);

        // System.out.println("[address1]  " + address1.toString());
        // System.out.println("[address2]  " + address2.toString());
        //
        // System.out.println("[compareTo] " + address1.compareTo(address2));
        // System.out.println("[equals]    " + address2.equals(address1));
        
        int[] data3 = {69, 0, 0, 115, 0, 0, 64, 0, 64, 17, 184, 97, 192, 168, 0, 1, 192, 168, 0, 199};
        int[] data4 = {69, 0, 0, 115, 0, 0, 64, 0, 64, 17, 192, 168, 0, 1, 192, 168, 0, 199};

        try {
            short id = 2115;
            boolean doNotFragment = true;
            boolean moreBits = true;
            short fragmentOffset = 5799;
            int timeToLive = IPv4Datagram.INITIALIZE_TTL;
            boolean decrementTTL = false;
            String sourceIp = "34.12.56.128";
            String destinationIp = "255.12.134.1";
            byte[] payload = { 111, 111, 111, 111, 111, 111, 111, 111 };

            IPv4Datagram one = new IPv4Datagram(id, doNotFragment, moreBits,
                    fragmentOffset, timeToLive, decrementTTL, sourceIp,
                    destinationIp, payload);
            System.out.println("[one] " + one.toString());
            
            byte[] temp = one.getBytes();
            
            for (int i = 0; i < temp.length; i++) {
                System.out.print(Integer.toBinaryString(temp[i]) + " ");
            }

            IPv4Datagram two = new IPv4Datagram(id, doNotFragment, moreBits,
                    fragmentOffset, timeToLive, decrementTTL, sourceIp,
                    destinationIp, payload);
            System.out.println("[two] " + two.toString());

//            two.modifyBytes();
            System.out.println("[two] " + two.toString());

//            System.out.println(one.validateChecksum(Arrays.copyOfRange(
//                    one.getBytes(), 0, 20)));
//            System.out.println(one.validateChecksum(Arrays.copyOfRange(
//                    two.getBytes(), 0, 20)));
            
            byte[] data = new byte[data4.length];
            
            for (int i = 0; i < data.length; i++) {
                data[i] = (byte)(data4[i]);
            }
            
            byte[] data2 = new byte[data3.length];
            
            for (int i = 0; i < data2.length; i++) {
                data2[i] = (byte)(data3[i]);
            }

            System.out.println("\n--------\n[Test with wiki data]");
//            one.testChecksum(data, data2);
            System.out.println("--------\n");
            
            data = Arrays.copyOfRange(one.getBytes(), 0, 20);
            data2 = Arrays.copyOfRange(two.getBytes(), 0, 20);
            
//            one.testChecksum(data, data2);

            System.out.println("[dest] " + one.getDestinationIP());
            
            System.out.println("[DNF  ]  " + one.isDoNotFragmentSet());
            System.out.println("[MBits]  " + one.isMoreBitSet());
            System.out.println("[offset] " + one.getFragmentOffset());
            
            
            
            
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

        // try {
        // System.out.println(InetAddress.getLocalHost());
        // } catch (UnknownHostException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }

        byte aa = -128;

        System.out.println(Byte.valueOf(aa).intValue());
    }

}